package com.beemans.common.app.bridge.request

import androidx.lifecycle.MutableLiveData
import com.beemans.common.app.data.bean.FriendResponse
import com.beemans.common.app.data.repository.DataRepository
import com.beemans.common.base.CommonViewModel
import com.beemans.common.ext.stringCallback

/**
 * @author tiamosu
 * @date 2021/6/8.
 */
class HttpViewModel : CommonViewModel() {
    val resultLiveData: MutableLiveData<FriendResponse> by lazy { MutableLiveData() }

    fun get() {
        DataRepository.instance.getFriend(stringCallback {
            onResult { result ->
                if (!result.isSuccess()) {
                    showToast(result.msg)
                    return@onResult
                }
                val response = result.getResponse<FriendResponse>(true)
                resultLiveData.value = response
            }
        })
    }

    fun post() {
        DataRepository.instance.postFriend(stringCallback {
            onResult { result ->
                if (!result.isSuccess()) {
                    showToast(result.msg)
                    return@onResult
                }
                val response = result.getResponse<FriendResponse>(true)
                resultLiveData.value = response
            }
        })
    }
}